import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';

@IonicPage()
@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {
    public title: boolean[] = [
        true, false, true, false, true, true, true,
        true, false, true, false, true, true, true,
        true, false, true, false, true, true, true,
        true, false, true, false, true, true, true,
        true, false, true, false, true, true, true
    ];

    public from:string;
    public from_id:number;

    constructor(public navCtrl: NavController, public navParams: NavParams) {
        this.from=this.navParams.get('from');
        this.from_id=this.navParams.get('from_id');
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad HomePage',this.from);
    }

    onDaySelect(day) {
        console.log(day);
    }

    //todo 1.基本跳转
    goDetail(id:number) {
        if(!this.from){
            this.navCtrl.push('DetailPage',{'id':id})
        }
    }

    goBack():void{
        if(this.from){
            this.navCtrl.pop();
        }
    }

    //todo 复杂跳转
    goDetailOrBack(id:number):void{
        if(!this.from){
            this.navCtrl.push('DetailPage',{'id':id})
        }else{
            //先请求后台发生关联，然后退回到之前页面
            this.navCtrl.pop().then(()=>{
                this.navCtrl.setPages([{page:'AboutDetailPage',params:{'id':this.from_id,'u_id':id}}]);
            });
            //this.navCtrl.push(this.from);//这种情况不能用push
        }
    }
}
